<?php
Yii::app()->clientScript->registerScriptFile($this->staticsPath."/frontend/js/jquery.js",CClientScript::POS_HEAD);
Yii::app()->clientScript->registerScriptFile($this->staticsPath."/js/bootstrap.min.js",CClientScript::POS_HEAD);
Yii::app()->clientScript->registerCssFile($this->staticsPath."/css/global.css");
Yii::app()->clientScript->registerCssFile($this->staticsPath."/css/index.css");
Yii::app()->clientScript->registerCssFile($this->staticsPath."/css/font-awesome.min.css");
Yii::app()->clientScript->registerCssFile($this->staticsPath."/Font-Awesome-3.2.1/css/font-awesome.min.css");
Yii::app()->clientScript->registerCssFile($this->staticsPath."/css/bootstrap.min.css");
Yii::app()->clientScript->registerScriptFile($this->staticsPath."/js/alert.js",CClientScript::POS_HEAD);

Yii::app()->clientScript->registerCss("CSS1","
    .cont_box img{
        height: 200px;
    }



");


?>
<style type="text/css">
    .morcon .reg {
        background: rgba(255, 255, 255, 0) none repeat scroll 0 0;
        border: medium none;
        color: #fff;
        font-size: 20px;
        left: 4%;
        position: absolute;
        top: 0;
    }
    .morcon .login {
        background: rgba(255, 255, 255, 0) none repeat scroll 0 0;
        border: medium none;
        color: #fff;
        display: block;
        font-size: 20px;
        left: 51%;
        position: absolute;
        top: 39%;
    }

    .wrap .header{
        width: 100%;
        position: relative;
        height: 300px;
    }
    .wrap .footer {
        height: 300px;
        position: relative;
        width: 100%;
    }


    .imgbg .box img {
        border-radius: 50%;
        height: 80%;
        left: 15px;
        position: absolute;
        top: 15px;
        width: 80%;
    }
    .wrap .header .hname {
        height: 200px;
        left: 170px;
        position: absolute;
        top: 144px;
        width: 200px;
    }
    .wrap .header .hname p{
        color: #0066b3;
        font-size: 20px;
    }
    .wrap .header .list {


        height: 80px;
        left: 25px;
        position: absolute;
        top: 25px;
        width: 80px;
    }
    .wrap .header .list a{
        color: #0066b3;
        font-size: 30px;
    }


    body{
        background: #f4f4f4 none repeat scroll 0 0;
    }
    .activity_list h3 {
        border-bottom: 1px solid #e2e1e1;
    }
    .scenic_sum h3 {
        color: #507fbd;
        font-size: 16px;
        margin-bottom: 1px;
        margin-top: 1px;
        min-height: 15px;
        padding-bottom: 22px;
    }
    .alert-danger, .alert-error {
        background-color: #f2dede;
        border-color: #eed3d7;
        color: #b94a48;
        text-align: center;
    }
    .rbox .fot{
        font-size: 16px;
    }
    .top_box .tx {
        float: left;
        height: 60px;
        margin-right: 10px;
        width: 60px;
    }
    .top_box .tx img {
        height: 100%;
        width: 100%;
    }
    .top_box .wz {
        display: block;
        float: left;
        margin-top: 10px;
        width: 130px;
    }
    .time {
        color: #555;
        font-size: 12px;
        padding-top: 8px;
    }
    .top_box .an {
        float: right;
        width: 100px;
    }
    .top_box .an .pinglun{
        background: url("<?php echo $this->staticsPath."/img/pinglun.png" ?>") no-repeat scroll 0 0 / 40px auto;
        height: 40px;
        width: 40px;
        cursor:pointer;
        float: right;
        margin-right: 10px;
    }
    .plbox {
        border-top: 1px dashed #c8bf92;
        margin-left: 30px;
        margin-top: 10px;
    }
    .con {
        padding: 10px 20px;
        word-break: break-all;
    }
    .book_box {
        background-color: #eee;
        margin-left: 20px;
        padding: 10px;
    }
    .book_box .book_thumb {
        float: left;
        height: 55px;
        overflow: hidden;
        width: 55px;
    }
    .book_box .book_thumb img{
        width: 100%;
    }
    .book_box .book_title{
        float: left;
        margin-left: 10px;
        height: 55px;
        font-size: 16px;
        line-height: 55px;
    }
    .header {
        color: #fff;
        overflow: hidden;
        position: fixed;
        top: 0;
        z-index: 700;
    }
    .wrap {
        margin-top: 45px;
    }
    .nm{
        color: #0066b3;
        margin-top:5px
    }
    .nav {
        background: rgb(249, 249, 249) none repeat scroll 0 0;
        border-top: 1px solid #ddd;
        bottom: 0;
        opacity: 0.9;
        padding: 6px 0 !important;
        position: fixed;
        width: 100%;
        height: 55px;
    }
    .nav .nav-box {
        color: #333;
        float: left;
        font-size: 14px;
        text-align: center;
        width: 33%;
        height: 100%;
    }
    .nav .nav-box.actt{
        color: #068043;
    }
</style>

<div class="data"  >
    <header class="homeHder header">
        <div class="hder_logo">我的孩子</div>
    </header>
    <section class="wrap">
    <div class="container-fluid">

    <div class="row">
    <ul class="activity bor" id="Xbox">
        <?php if($list){ ?>
            <?php foreach($list as $v){ ?>
                <li>
                    <div class="sb">
                        <div class="top_box">
                            <?php if(!$v['image']){ ?>
                                <?php if($v['sex'] ==1){ ?>
                                    <div class="tx"><img src="<?php echo $this->staticsPath."/img/tx1.jpg" ?>" /></div>
                                <?php }else{ ?>
                                    <div class="tx"><img src="<?php echo $this->staticsPath."/img/tx2.jpg" ?>" /></div>
                                <?php } ?>
                            <?php }else{ ?>
                                <div class="tx"><img src="<?php echo $v['image']; ?>" /></div>
                            <?php } ?>
                            <div class="wz">
                                <div class="name"><?php echo $v['user_name']  ?></div>
                                <div class="time"><?php echo date('Y/m/d H:i',$v['create_time'])  ?></div>
                            </div>
                            <div class="an">
                                <div data-aid="<?php echo $v['bid']  ?>" data-id="<?php echo $v['id']  ?>" class="pinglun"></div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="con"><?php echo CHtml::decode($v['content']);  ?></div>
                    <div class="book_box clearfix">
                        <div class="book_thumb">
                            <img src="<?php echo Yii::app()->params['webPath'].$v['thumb']; ?>" />
                        </div>
                        <div class="book_title"><?php echo CHtml::decode($v['title']);  ?></div>
                    </div>
                    <?php $comment_info =  BookComment::model()->getComment($v['id']); ?>
                    <div id="plbox_<?php echo $v['id'] ?>"  class="plbox">
                    <?php if($comment_info){ ?>

                            <?php foreach($comment_info as $vv){ ?>

                                <div class="sb">
                                    <div class="top_box">
                                        <?php if($vv['role']==1){ ?>
                                            <div class="name"><span class="nm"><?php echo $vv['user_name'] ?></span>：<?php echo $vv['content'] ?></div>
                                        <?php }elseif($vv['role']==2){ ?>
                                            <div class="name"><span class="nm"><?php echo $v['user_name'].'的'.$vv['is_relation'] ?></span>：<?php echo $vv['content'] ?></div>
                                        <?php }elseif($vv['role']==3){ ?>
                                            <div class="name"><span class="nm"><?php echo $vv['user_name'].'教师' ?></span>：<?php echo $vv['content'] ?>&nbsp;&nbsp;&nbsp;[<span style="color: darkred"><?php echo $vv['start'].'星'; ?>]&nbsp;</span></div>
                                        <?php } ?>
                                    </div>
                                    <div class="clearfix"></div>
                                </div>

                            <?php } ?>

                    <?php } ?>
                    </div>
                </li>
            <?php } ?>
        <?php }else{ ?>
        <li>
            <div class="alert alert-error" style="" id="alt">
                暂无任何数据
            </div>
        </li>
        <?php } ?>
    </ul>
    <div class="alert alert-info" style="text-align: center; display: none;" id="loadings">
        <i class="fa fa-circle-o-notch fa-spin"></i>&nbsp;正在加载中...
    </div>

    <div class="alert alert-error" style="display: none;" id="alt">
        没有更多啦！
    </div>
    </div>
    </div>




    <script type="text/javascript">
        $(function(){
            var currentPage = 0;
            var isloading = false;
            $(window).scroll(function(){
                if($(window).scrollTop() + 100 >= $(document).height() - $(window).height()){
                    if (isloading == true){  //如果loading为真 则return false;
                        return false;
                    }
                    currentPage = currentPage + 1;
                    isloading = true; //为真了
                    $.ajax({
                        url:'<?php echo $this->createUrl('ajaxChild') ?>',
                        type : 'GET',
                        data:{
                            page:currentPage,
                            openid:'<?php echo $openid ?>',
                        },
                        dataType:'html',
                        beforeSend : function() {
                            $('#loadings').show();
                            isloading = true;
                        },
                        success : function (data,response,status) {
                            if(data){
                                $('#Xbox').append(data);
                                isloading = false;
                                $('#loadings').hide();
                            }else{
                                isloading = true;
                                $('#loadings').hide();
                                $('#alt').show();
                            }
                        }
                    });
                }
            });

        });
    </script>


    </section>
    <br>
    <br>
    <br>
    <br>
</div>

<nav class="nav">
    <a href="<?php echo Yii::app()->createUrl('index/list1',array('openid'=>$openid)) ?>" class="">
        <div class="nav-box">
            <i class="fa fa-book"></i>书目
        </div>
    </a>
    <?php if($user_info->role==2){ ?>
        <a href="<?php  echo Yii::app()->createUrl('user/child',array('openid'=>$openid)); ?>" class="">
            <div class="nav-box actt">
                <i class="fa fa-user"></i>我的孩子
            </div>
        </a>
    <?php }else{ ?>
        <a href="<?php  echo Yii::app()->createUrl('user/student',array('openid'=>$openid)); ?>" class="">
            <div class="nav-box">
                <i class="fa fa-users"></i>我的学生
            </div>
        </a>
    <?php } ?>
    <a href="<?php echo Yii::app()->createUrl('user/index',array('openid'=>$openid)); ?>" class="">
        <div class="nav-box">
            <i class="fa fa-home"></i>个人中心
        </div>
    </a>
</nav>

<div class="modal fade" id="XcommLs" data-id="1" tabindex="-1" role="dialog" aria-labelledby="linkModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <!-- 登陆页面注册提示 -->
        <div class="modal-content text-left">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">请输入评价</h4>
            </div>
            <div class="modal-body">
                <form>

                    <div class="form-group">
                        <label for="exampleInputname1">评价：</label>
                        <textarea data-id="" data-aid="" style="height:200px" class="form-control" id="lspl" ></textarea>
                    </div>
                    <button type="button"  id="lsSubmit" class="btn btn-primary btn-block btn-lg">确认提交</button>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="Xalert" data-id="1" tabindex="-1" role="dialog" aria-labelledby="linkModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <!-- 登陆页面注册提示 -->
        <div class="modal-content text-left">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">提示</h4>
            </div>
            <div class="modal-body">
                <p id="alertMassage"></p>
                <button type="button" style="margin-top: 20px" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    $(function(){

        $("body").on('click',".pinglun",function(event){
            event.stopPropagation();
            var _this = $(this);
            var cid = _this.attr('data-id');
            var bid = _this.attr('data-aid');
            $("#lspl").val('');
            $("#lspl").attr('data-id',cid);
            $("#lspl").attr('data-aid',bid);
            $("#XcommLs").modal();

        });
    });

    $("#lsSubmit").click(function(){
        var pl = $("#lspl").val();
        var cid = $("#lspl").attr('data-id');
        var bid = $("#lspl").attr('data-aid');
        if (pl.length == 0 || pl.length < 10) {
            $("#alertMassage").html("评论不能为空或小于10个字符限制");
            $("#Xalert").modal();
            setTimeout(function(){$("#Xalert").modal('hide')},2000);
            return;
        };
        $.ajax({
            type: "POST",
            url: '<?php echo Yii::app()->createUrl('index/ajaxPl'); ?>',
            data: {
                bid:'<?php echo $book_info->id ?>',
                cid:cid,
                pl:pl,
                bid:bid
            },
            dataType: "json",
            success: function (data) {
                if (data) {
                    if(data.status==1){
                        $("#alertMassage").html(data.message);
                        $("#Xalert").modal();
                        setTimeout(function(){$("#Xalert").modal('hide')},2000);

                        $("#XcommLs").modal('hide');
                        $("#lspl").val('');
                        var html = '';
                        html +='<div class="sb">';
                        html +='<div class="top_box">';
                        html +='<div class="name"><span class="nm">我</span>：'+pl+'&nbsp;&nbsp;&nbsp;[<span style="color: darkred">'+start+'星]&nbsp;</span></div>';
                        html +='</div>';
                        html +='<div class="clearfix"></div>';
                        html +='</div>';
                        $("#plbox_"+cid).prepend(html);
                    }else{
                        ljydlock = true;
                        $("#alertMassage").html(data.message);
                        $("#Xalert").modal();
                        setTimeout(function(){$("#Xalert").modal('hide')},2000);
                        $("#XcommLs").modal('hide');
                        $("#lspl").val('');
                    }
                }else{
                    $("#alertMassage").html('评论失败');
                    $("#Xalert").modal();
                    setTimeout(function(){$("#Xalert").modal('hide')},2000);
                }
            }
        });
    });



</script>